package com.ssmsq.multidatabase.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssmsq.multidatabase.entity.YwzxXiangmu;
import com.ssmsq.multidatabase.mapper.YwzxXiangmuMapper;
import com.ssmsq.multidatabase.service.SysRoleService;
import com.ssmsq.multidatabase.service.YwzxXiangmuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author sss
 */
@DS("slave_1")
@Service
public class YwzxXiangmuServiceImpl extends ServiceImpl<YwzxXiangmuMapper, YwzxXiangmu> implements YwzxXiangmuService {

    @Resource
    private SysRoleService sysRoleService;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public boolean saveOne(Integer b, Date date) {
        boolean save = false;
        try {
            YwzxXiangmu ywzxXiangmu = new YwzxXiangmu();
            ywzxXiangmu.setBh("1");
            ywzxXiangmu.setMc("ywzx_" + date);
            ywzxXiangmu.setLxid("100");
            ywzxXiangmu.setXmzt("1");
            ywzxXiangmu.setYhid("1");
            ywzxXiangmu.setBmid("1");
            ywzxXiangmu.setSfsc(false);
            save = save(ywzxXiangmu);

            save = sysRoleService.saveOne(b, date);
            if(!save) {
                throw new RuntimeException();
            }
        } catch (Exception e) {
            throw e;
        }
        return save;
    }

}
